

define('main', function (require, exports, module) {
    var el = $('#calendar');
    var now = new Date();
    var day = now.getDate();
    var weekDays = '<ul class="week-days">\
            <li>Mon</li>\
            <li>Tue</li>\
            <li>Wen</li>\
            <li>Thu</li>\
            <li>Fri</li>\
            <li>Sat</li>\
            <li>Sun</li>\
        </ul>';
    var days = $('<ul class="days">');
    var html = [];

    // console.log(getFirstDay(now));
    for (var i = 0; i < getFirstDay(now); i++) {
        html.push('<li class="empty">&nbsp</li>'); 
    }
    for (var i = 1; i <= getLastDate(now); i++) {
        var className = '';
        if (i == day) {
            className = 'today';
        }
        var kcal = 0;
        if (i < day) {
            kcal = Math.floor(Math.random() * 3000);
        }

        html.push('<li><div class="inner"><div class="background"><em>' + i + '</em><strong>' + kcal + '</strong></div></div></li>'); 
    }
    days.append(html.join(''));
    el.append(weekDays);
    el.append(days);


    function getFirstDay (date) {
        var year = now.getFullYear();
        var month = now.getMonth();
        var date = new Date(year, month, 1);
        return date.getDay();
    }

    function getLastDate (date) {
        var year = now.getFullYear();
        var month = now.getMonth();
        var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        if (year % 4 == 0) {
            days[1] = 29;
        }
        return days[month];
    }
});
